#region "Copyright (C) Lenny Granovsky. 2005-2013"
//This program is free software distribute under the terms of the GNU General Public License as published by
//the Free Software Foundation. Please read AssemblyInfo.cs file for more information.
#endregion

using System;
using System.Collections.Generic;
using System.Text;

namespace Web.Enhancements.Rest
{
    /// <summary>
    /// <para>Attribute that indicates method as being able to be rendered to JS Client and callable from Client as REST service. </para>
    /// <para>This interface serves as security clearance for the runtime to allow IIS requests going to/from the method. </para>
    /// <para>This attribute provides method with ability to set sepcific parameters how call should be handled, such as SessionMode, 
    /// mouse position handling, and HTTP MIME type for the response.</para>
    /// </summary>
    [Serializable()]
    [AttributeUsage(AttributeTargets.Method)]
    public class WebRestMethodAttribute : Attribute
    {
        /// <summary>
        /// Gets or sets boolean value where or not client handler should handle mouse location before 
        /// submitting the request to the server. 
        /// This allows callback function to handle calling location to display the content at specific position.
        /// </summary>
        public bool HandleClientMousePosition { get; set; }
        /// <summary>
        /// Gets or sets page session state mode that should be maintained when method call occurs. 
        /// </summary>
        public System.Web.SessionState.SessionStateBehavior SessionMode { get; set; }
        /// <summary>
        /// Gets or sets the HTTP MIME type that response will write to the stream upon method completion.
        /// </summary>
        public string ContentType { get; set; }
        /// <summary>
        /// Gets or sets the HTTP Content-Disposition header that response will write to the stream upon method completion.
        /// </summary>
        public string ContentDisposition { get; set; }
        /// <summary>
        /// Gets or sets the JSON serializer type when the JSON is used as output. 
        /// The default value is standard JavaScriptSerializer.
        /// </summary>
        public JsonSerializerType JsonSerializer { get; set; }

        public WebRestMethodAttribute()
        {
            this.SessionMode = System.Web.SessionState.SessionStateBehavior.Disabled;
            this.ContentType = "text/html";
            this.ContentDisposition = "";
            this.JsonSerializer = JsonSerializerType.JavaScriptSerializer;
        }

        public WebRestMethodAttribute(bool handleClientMousePosition)
            : this()
        {
            this.HandleClientMousePosition = handleClientMousePosition;
        }

        public WebRestMethodAttribute(bool handleClientMousePosition, System.Web.SessionState.SessionStateBehavior sessionMode)
            : this()
        {
            this.HandleClientMousePosition = handleClientMousePosition;
            this.SessionMode = sessionMode;
        }

        public WebRestMethodAttribute(System.Web.SessionState.SessionStateBehavior sessionMode)
            : this()
        {
            this.SessionMode = sessionMode;
        }
    }

    /// <summary>
    /// The JSON serializer that should be used to output the JSON data.
    /// </summary>
    public enum JsonSerializerType
    {
        /// <summary>
        /// The Microsoft System.Web.Script.Serialization.JavaScriptSerializer.
        /// </summary>
        JavaScriptSerializer,
        /// <summary>
        /// The Microsoft System.Runtime.Serialization.Json.DataContractJsonSerializer.
        /// </summary>
        DataContractJsonSerializer,
        /// <summary>
        /// The Custom JsonSerializer based on external configuration.
        /// </summary>
        CustomJsonSerializer
    }
}
